home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / WebRoot / cfide / scripts / wddx.js
Encoding:
JavaScript  |  2001-06-13  |  21.9 KB  |  812 lines

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. //    Filename:        wddx.js
  4. //
  5. //    Authors:        Simeon Simeonov (simeons@allaire.com)
  6. //                    Nate Weiss (nweiss@icesinc.com)
  7. //
  8. //    Last Modified:    February 2, 2001
  9. //
  10. ///////////////////////////////////////////////////////////////////////////
  11.  
  12.  
  13. ///////////////////////////////////////////////////////////////////////////
  14. //
  15. //    WddxSerializer
  16. //
  17. ///////////////////////////////////////////////////////////////////////////
  18.  
  19.  
  20. ///////////////////////////////////////////////////////////////////////////
  21. //     serializeValue() serializes any value that can be serialized
  22. //    returns true/false
  23. function wddxSerializer_serializeValue(obj)
  24. {
  25.     var bSuccess = true;
  26.     var val;
  27.  
  28.     if (obj == null)
  29.     {
  30.         // Null value
  31.         this.write("<null/>");
  32.     }
  33.     else if (typeof(val = obj.valueOf()) == "string")
  34.     {
  35.         // String value
  36.         this.serializeString(val);
  37.     }
  38.     else if (typeof(val = obj.valueOf()) == "number")
  39.     {
  40.         // Distinguish between numbers and date-time values
  41.  
  42.         if (
  43.             typeof(obj.getTimezoneOffset) == "function" &&
  44.             typeof(obj.toGMTString) == "function")
  45.         {
  46.             // Possible Date
  47.             // Note: getYear() fix is from David Flanagan's 
  48.             // "JS: The Definitive Guide". This code is Y2K safe.
  49.             this.write("<dateTime>" + 
  50.                 (obj.getYear() < 1000 ? 1900+obj.getYear() : obj.getYear()) + "-" + (obj.getMonth() + 1) + "-" + obj.getDate() +
  51.                 "T" + obj.getHours() + ":" + obj.getMinutes() + ":" + obj.getSeconds());
  52.             if (this.useTimezoneInfo)
  53.             {
  54.                 this.write(this.timezoneString);
  55.             }
  56.             this.write("</dateTime>");
  57.         }
  58.         else
  59.         {
  60.             // Number value
  61.             this.write("<number>" + val + "</number>");
  62.         }
  63.     }
  64.     else if (typeof(val = obj.valueOf()) == "boolean")
  65.     {
  66.         // Boolean value
  67.         this.write("<boolean value='" + val + "'/>");
  68.     }
  69.     else if (typeof(obj) == "object")
  70.     {
  71.         if (typeof(obj.wddxSerialize) == "function")
  72.         {
  73.             // Object knows how to serialize itself
  74.             bSuccess = obj.wddxSerialize(this);
  75.         }
  76.         else if (
  77.             typeof(obj.join) == "function" &&
  78.             typeof(obj.reverse) == "function" &&
  79.             typeof(obj.sort) == "function" &&
  80.             typeof(obj.length) == "number")
  81.         {
  82.             // Possible Array
  83.             this.write("<array length='" + obj.length + "'>");
  84.             for (var i = 0; bSuccess && i < obj.length; ++i)
  85.             {
  86.                 bSuccess = this.serializeValue(obj[i]);
  87.             }
  88.             this.write("</array>");
  89.         }
  90.         else
  91.         {
  92.             // Some generic object; treat it as a structure
  93.  
  94.             // Use the wddxSerializationType property as a guide as to its type            
  95.             if (typeof(obj.wddxSerializationType) == 'string')
  96.             {              
  97.                 this.write('<struct type="'+ obj.wddxSerializationType +'">')
  98.             }  
  99.             else
  100.             {                                                       
  101.                 this.write("<struct>");
  102.             }
  103.                         
  104.             for (var prop in obj)
  105.             {  
  106.                 if (prop != 'wddxSerializationType')
  107.                 {                          
  108.                     bSuccess = this.serializeVariable(prop, obj[prop]);
  109.                     if (! bSuccess)
  110.                     {
  111.                         break;
  112.                     }
  113.                 }
  114.             }
  115.             
  116.             this.write("</struct>");
  117.         }
  118.     }
  119.     else
  120.     {
  121.         // Error: undefined values or functions
  122.         bSuccess = false;
  123.     }
  124.  
  125.     // Successful serialization
  126.     return bSuccess;
  127. }
  128.  
  129.  
  130.  
  131. ///////////////////////////////////////////////////////////////////////////
  132. // serializeAttr() serializes an attribute (such as a var tag) using JavaScript 
  133. // functionality available in NS 3.0 and above
  134. function wddxSerializer_serializeAttr(s)
  135. {
  136.     for (var i = 0; i < s.length; ++i)
  137.     {
  138.         this.write(this.at[s.charAt(i)]);
  139.     }
  140. }
  141.  
  142.  
  143. ///////////////////////////////////////////////////////////////////////////
  144. // serializeAttrOld() serializes a string using JavaScript functionality
  145. // available in IE 3.0. We don't support special characters for IE3, so
  146. // just throw the unencoded text and hope for the best
  147. function wddxSerializer_serializeAttrOld(s)
  148. {
  149.     this.write(s);
  150. }
  151.  
  152.  
  153. ///////////////////////////////////////////////////////////////////////////
  154. // serializeString() serializes a string using JavaScript functionality
  155. // available in NS 3.0 and above
  156. function wddxSerializer_serializeString(s)
  157. {
  158.     this.write("<string>");
  159.     for (var i = 0; i < s.length; ++i)
  160.     {
  161.         this.write(this.et[s.charAt(i)]);
  162.     }
  163.     this.write("</string>");
  164. }
  165.  
  166.  
  167. ///////////////////////////////////////////////////////////////////////////
  168. // serializeStringOld() serializes a string using JavaScript functionality
  169. // available in IE 3.0
  170. function wddxSerializer_serializeStringOld(s)
  171. {
  172.     this.write("<string><![CDATA[");
  173.     
  174.     pos = s.indexOf("]]>");
  175.     if (pos != -1)
  176.     {
  177.         startPos = 0;
  178.         while (pos != -1)
  179.         {
  180.             this.write(s.substring(startPos, pos) + "]]>]]><![CDATA[");
  181.             
  182.             startPos = pos + 3;
  183.             if (startPos < s.length)
  184.             {
  185.                 pos = s.indexOf("]]>", startPos);
  186.             }
  187.             else
  188.             {
  189.                 // Work around bug in indexOf()
  190.                 // "" will be returned instead of -1 if startPos > length
  191.                 pos = -1;
  192.             }                               
  193.         }
  194.         this.write(s.substring(startPos, s.length));
  195.     }
  196.     else
  197.     {
  198.         this.write(s);
  199.     }
  200.             
  201.     this.write("]]></string>");
  202. }
  203.  
  204.  
  205. ///////////////////////////////////////////////////////////////////////////
  206. // serializeVariable() serializes a property of a structure
  207. // returns true/false
  208. function wddxSerializer_serializeVariable(name, obj)
  209. {
  210.     var bSuccess = true;
  211.     
  212.     if (typeof(obj) != "function")
  213.     {
  214.         this.write("<var name='");
  215.         this.preserveVarCase ? this.serializeAttr(name) : this.serializeAttr(name.toLowerCase());
  216.         this.write("'>");
  217.  
  218.         bSuccess = this.serializeValue(obj);
  219.         this.write("</var>");
  220.     }
  221.  
  222.     return bSuccess;
  223. }
  224.  
  225.  
  226. ///////////////////////////////////////////////////////////////////////////
  227. // write() appends text to the wddxPacket buffer
  228. function wddxSerializer_write(str)
  229. {
  230.     this.wddxPacket[this.wddxPacket.length] = str;
  231. }
  232.  
  233.  
  234. ///////////////////////////////////////////////////////////////////////////
  235. // writeOld() appends text to the wddxPacket buffer using IE 3.0 (JS 1.0)
  236. // functionality. Unfortunately, the += operator has quadratic complexity
  237. // which will cause slowdowns for large packets.
  238. function wddxSerializer_writeOld(str)
  239. {
  240.     this.wddxPacket += str;
  241. }
  242.  
  243.  
  244. ///////////////////////////////////////////////////////////////////////////
  245. // initPacket() initializes the WDDX packet
  246. function wddxSerializer_initPacket()
  247. {
  248.     this.wddxPacket = new Array();
  249. }
  250.  
  251.  
  252. ///////////////////////////////////////////////////////////////////////////
  253. // initPacketOld() initializes the WDDX packet for use with IE 3.0 (JS 1.0)
  254. function wddxSerializer_initPacketOld()
  255. {
  256.     this.wddxPacket = "";
  257. }
  258.  
  259.  
  260. ///////////////////////////////////////////////////////////////////////////
  261. // extractPacket() extracts the WDDX packet as a string
  262. function wddxSerializer_extractPacket()
  263. {
  264.     return this.wddxPacket.join("");
  265. }
  266.  
  267.  
  268. ///////////////////////////////////////////////////////////////////////////
  269. // extractPacketOld() extracts the WDDX packet as a string (IE 3.0/JS 1.0)
  270. function wddxSerializer_extractPacketOld()
  271. {
  272.     return this.wddxPacket;
  273. }
  274.  
  275.  
  276. ///////////////////////////////////////////////////////////////////////////
  277. // serialize() creates a WDDX packet for a given object
  278. // returns the packet on success or null on failure
  279. function wddxSerializer_serialize(rootObj)
  280. {
  281.     this.initPacket();
  282.  
  283.     this.write("<wddxPacket version='1.0'><header/><data>");
  284.     var bSuccess = this.serializeValue(rootObj);
  285.     this.write("</data></wddxPacket>");
  286.  
  287.     if (bSuccess)
  288.     {
  289.         return this.extractPacket();
  290.     }
  291.     else
  292.     {    
  293.         return null;
  294.     }
  295. }
  296.  
  297.  
  298. ///////////////////////////////////////////////////////////////////////////
  299. // WddxSerializer() binds the function properties of the object
  300. function WddxSerializer()
  301. {
  302.     // Compatibility section
  303.     if (navigator.appVersion != "" && navigator.appVersion.indexOf("MSIE 3.") == -1)
  304.     {
  305.         // Character encoding table
  306.         
  307.         // Encoding table for strings (CDATA)   
  308.         var et = new Array();
  309.  
  310.         // Numbers to characters table and 
  311.         // characters to numbers table
  312.         var n2c = new Array();
  313.         var c2n = new Array();
  314.     
  315.         // Encoding table for attributes (i.e. var=str)
  316.         var at = new Array();
  317.  
  318.         for (var i = 0; i < 256; ++i)
  319.         {
  320.             // Build a character from octal code
  321.             var d1 = Math.floor(i/64);
  322.             var d2 = Math.floor((i%64)/8);
  323.             var d3 = i%8;
  324.             var c = eval("\"\\" + d1.toString(10) + d2.toString(10) + d3.toString(10) + "\"");
  325.     
  326.             // Modify character-code conversion tables        
  327.             n2c[i] = c;
  328.             c2n[c] = i; 
  329.             
  330.             // Modify encoding table
  331.             if (i < 32 && i != 9 && i != 10 && i != 13)
  332.             {
  333.                 // Control characters that are not tabs, newlines, and carriage returns
  334.                 
  335.                 // Create a two-character hex code representation
  336.                 var hex = i.toString(16);
  337.                 if (hex.length == 1)
  338.                 {
  339.                     hex = "0" + hex;
  340.                 }
  341.                 
  342.                 et[n2c[i]] = "<char code='" + hex + "'/>";
  343.  
  344.                 // strip control chars from inside attrs
  345.                 at[n2c[i]] = "";
  346.  
  347.             }
  348.             else if (i < 128)
  349.             {
  350.                 // Low characters that are not special control characters
  351.                 et[n2c[i]] = n2c[i];
  352.  
  353.                 // attr table
  354.                 at[n2c[i]] = n2c[i];
  355.             }
  356.             else
  357.             {
  358.                 // High characters
  359.                 et[n2c[i]] = "&#x" + i.toString(16) + ";";
  360.                 at[n2c[i]] = "&#x" + i.toString(16) + ";";
  361.             }
  362.         }    
  363.     
  364.         // Special escapes for CDATA encoding
  365.         et["<"] = "<";
  366.         et[">"] = ">";
  367.         et["&"] = "&";
  368.  
  369.         // Special escapes for attr encoding
  370.         at["<"] = "<";
  371.         at[">"] = ">";
  372.         at["&"] = "&";
  373.         at["'"] = "'";
  374.         at["\""] = """;
  375.                 
  376.         // Store tables
  377.         this.n2c = n2c;
  378.         this.c2n = c2n;
  379.         this.et = et;    
  380.         this.at = at;
  381.         
  382.            // The browser is not MSIE 3.x
  383.         this.serializeString = wddxSerializer_serializeString;
  384.         this.serializeAttr = wddxSerializer_serializeAttr;
  385.         this.write = wddxSerializer_write;
  386.         this.initPacket = wddxSerializer_initPacket;
  387.         this.extractPacket = wddxSerializer_extractPacket;
  388.     }
  389.     else
  390.     {
  391.         // The browser is most likely MSIE 3.x, it is NS 2.0 compatible
  392.         this.serializeString = wddxSerializer_serializeStringOld;
  393.         this.serializeAttr = wddxSerializer_serializeAttrOld;
  394.         this.write = wddxSerializer_writeOld;
  395.         this.initPacket = wddxSerializer_initPacketOld;
  396.         this.extractPacket = wddxSerializer_extractPacketOld;
  397.     }
  398.     
  399.     // Setup timezone information
  400.     
  401.     var tzOffset = (new Date()).getTimezoneOffset();
  402.  
  403.     // Invert timezone offset to convert local time to UTC time
  404.     if (tzOffset >= 0)
  405.     {
  406.         this.timezoneString = '-';
  407.     }
  408.     else
  409.     {
  410.         this.timezoneString = '+';
  411.     }
  412.     this.timezoneString += Math.floor(Math.abs(tzOffset) / 60) + ":" + (Math.abs(tzOffset) % 60);
  413.     
  414.     // Common properties
  415.     this.preserveVarCase = false;
  416.     this.useTimezoneInfo = true;
  417.  
  418.     // Common functions
  419.     this.serialize = wddxSerializer_serialize;
  420.     this.serializeValue = wddxSerializer_serializeValue;
  421.     this.serializeVariable = wddxSerializer_serializeVariable;
  422. }
  423.  
  424.  
  425. ///////////////////////////////////////////////////////////////////////////
  426. //
  427. //    WddxRecordset
  428. //
  429. ///////////////////////////////////////////////////////////////////////////
  430.  
  431.  
  432. ///////////////////////////////////////////////////////////////////////////
  433. // isColumn(name) returns true/false based on whether this is a column name
  434. function wddxRecordset_isColumn(name)
  435. {
  436.     // Columns must be objects
  437.     // WddxRecordset extensions might use properties prefixed with 
  438.     // _private_ and these will not be treated as columns
  439.     return (typeof(this[name]) == "object" && 
  440.             name.indexOf("_private_") == -1);
  441. }
  442.  
  443.  
  444. ///////////////////////////////////////////////////////////////////////////
  445. // getRowCount() returns the number of rows in the recordset
  446. function wddxRecordset_getRowCount()
  447. {
  448.     var nRowCount = 0;
  449.     for (var col in this)
  450.     {
  451.         if (this.isColumn(col))
  452.         {
  453.             nRowCount = this[col].length;
  454.             break;
  455.         }
  456.     }
  457.     return nRowCount;
  458. }
  459.  
  460.  
  461. ///////////////////////////////////////////////////////////////////////////
  462. // addColumn(name) adds a column with that name and length == getRowCount()
  463. function wddxRecordset_addColumn(name)
  464. {
  465.     var nLen = this.getRowCount();
  466.     var colValue = new Array(nLen);
  467.     for (var i = 0; i < nLen; ++i)
  468.     {
  469.         colValue[i] = null;
  470.     }
  471.     this[this.preserveFieldCase ? name : name.toLowerCase()] = colValue;
  472. }
  473.  
  474.  
  475. ///////////////////////////////////////////////////////////////////////////
  476. // addRows() adds n rows to all columns of the recordset
  477. function wddxRecordset_addRows(n)
  478. {
  479.     for (var col in this)
  480.     {
  481.         if (this.isColumn(col))
  482.         {
  483.             var nLen = this[col].length;
  484.             for (var i = nLen; i < nLen + n; ++i)
  485.             {
  486.                 this[col][i] = null;
  487.             }
  488.         }
  489.     }
  490. }
  491.  
  492.  
  493. ///////////////////////////////////////////////////////////////////////////
  494. // getField() returns the element in a given (row, col) position
  495. function wddxRecordset_getField(row, col)
  496. {
  497.     return this[this.preserveFieldCase ? col : col.toLowerCase()][row];
  498. }
  499.  
  500.  
  501. ///////////////////////////////////////////////////////////////////////////
  502. // setField() sets the element in a given (row, col) position to value
  503. function wddxRecordset_setField(row, col, value)
  504. {
  505.     this[this.preserveFieldCase ? col : col.toLowerCase()][row] = value;
  506. }
  507.  
  508.  
  509. ///////////////////////////////////////////////////////////////////////////
  510. // wddxSerialize() serializes a recordset
  511. // returns true/false
  512. function wddxRecordset_wddxSerialize(serializer)
  513. {
  514.     // Create an array and a list of column names
  515.     var colNamesList = "";
  516.     var colNames = new Array();
  517.     var i = 0;
  518.     for (var col in this)
  519.     {
  520.         if (this.isColumn(col))
  521.         {
  522.             colNames[i++] = col;
  523.  
  524.             if (colNamesList.length > 0)
  525.             {
  526.                 colNamesList += ",";
  527.             }
  528.             colNamesList += col;            
  529.         }
  530.     }
  531.     
  532.     var nRows = this.getRowCount();
  533.     
  534.     serializer.write("<recordset rowCount='" + nRows + "' fieldNames='" + colNamesList + "'>");
  535.     
  536.     var bSuccess = true;
  537.     for (i = 0; bSuccess && i < colNames.length; i++)
  538.     {
  539.         var name = colNames[i];
  540.         serializer.write("<field name='" + name + "'>");
  541.         
  542.         for (var row = 0; bSuccess && row < nRows; row++)
  543.         {
  544.             bSuccess = serializer.serializeValue(this[name][row]);
  545.         }
  546.         
  547.         serializer.write("</field>");
  548.     }
  549.     
  550.     serializer.write("</recordset>");
  551.     
  552.     return bSuccess;
  553. }
  554.  
  555.  
  556. ///////////////////////////////////////////////////////////////////////////
  557. // dump(escapeStrings) returns an HTML table with the recordset data
  558. // It is a convenient routine for debugging and testing recordsets
  559. // The boolean parameter escapeStrings determines whether the <>& 
  560. // characters in string values are escaped as <>&
  561. function wddxRecordset_dump(escapeStrings)
  562. {
  563.     // Get row count
  564.     var nRows = this.getRowCount();
  565.     
  566.     // Determine column names
  567.     var colNames = new Array();
  568.     var i = 0;
  569.     for (var col in this)
  570.     {
  571.         if (typeof(this[col]) == "object")
  572.         {
  573.             colNames[i++] = col;
  574.         }
  575.     }
  576.  
  577.     // Build table headers    
  578.     var o = "<table border=1><tr><td><b>RowNumber</b></td>";
  579.     for (i = 0; i < colNames.length; ++i)
  580.     {
  581.         o += "<td><b>" + colNames[i] + "</b></td>";
  582.     }
  583.     o += "</tr>";
  584.     
  585.     // Build data cells
  586.     for (var row = 0; row < nRows; ++row)
  587.     {
  588.         o += "<tr><td>" + row + "</td>";
  589.         for (i = 0; i < colNames.length; ++i)
  590.         {
  591.             var elem = this.getField(row, colNames[i]);
  592.             if (escapeStrings && typeof(elem) == "string")
  593.             {
  594.                 var str = "";
  595.                 for (var j = 0; j < elem.length; ++j)
  596.                 {
  597.                     var ch = elem.charAt(j);
  598.                     if (ch == '<')
  599.                     {
  600.                         str += "<";
  601.                     }
  602.                     else if (ch == '>')
  603.                     {
  604.                         str += ">";
  605.                     }
  606.                     else if (ch == '&')
  607.                     {
  608.                         str += "&";
  609.                     }
  610.                     else
  611.                     {
  612.                         str += ch;
  613.                     }
  614.                 }            
  615.                 o += ("<td>" + str + "</td>");
  616.             }
  617.             else
  618.             {
  619.                 o += ("<td>" + elem + "</td>");
  620.             }
  621.         }
  622.         o += "</tr>";
  623.     }
  624.  
  625.     // Close table
  626.     o += "</table>";
  627.  
  628.     // Return HTML recordset dump
  629.     return o;    
  630. }
  631.  
  632.  
  633. ///////////////////////////////////////////////////////////////////////////
  634. // WddxRecordset([flagPreserveFieldCase]) creates an empty recordset.
  635. // WddxRecordset(columns [, flagPreserveFieldCase]) creates a recordset 
  636. //   with a given set of columns provided as an array of strings.
  637. // WddxRecordset(columns, rows [, flagPreserveFieldCase]) creates a 
  638. //   recordset with these columns and some number of rows.
  639. // In all cases, flagPreserveFieldCase determines whether the exact case
  640. //   of field names is preserved. If omitted, the default value is false
  641. //   which means that all field names will be lowercased.
  642. function WddxRecordset()
  643. {
  644.     // Add default properties
  645.     this.preserveFieldCase = false;
  646.  
  647.     // Add extensions
  648.     if (typeof(wddxRecordsetExtensions) == "object")
  649.     {
  650.         for (var prop in wddxRecordsetExtensions)
  651.         {
  652.             // Hook-up method to WddxRecordset object
  653.             this[prop] = wddxRecordsetExtensions[prop]
  654.         }
  655.     }
  656.  
  657.     // Add built-in methods
  658.     this.getRowCount = wddxRecordset_getRowCount;
  659.     this.addColumn = wddxRecordset_addColumn;
  660.     this.addRows = wddxRecordset_addRows;
  661.     this.isColumn = wddxRecordset_isColumn;
  662.     this.getField = wddxRecordset_getField;
  663.     this.setField = wddxRecordset_setField;
  664.     this.wddxSerialize = wddxRecordset_wddxSerialize;
  665.     this.dump = wddxRecordset_dump;
  666.     
  667.     // Perfom any needed initialization
  668.     if (WddxRecordset.arguments.length > 0)
  669.     {
  670.         if (typeof(val = WddxRecordset.arguments[0].valueOf()) == "boolean")
  671.         {
  672.             // Case preservation flag is provided as 1st argument
  673.             this.preserveFieldCase = WddxRecordset.arguments[0];
  674.         }
  675.         else
  676.         {
  677.             // First argument is the array of column names
  678.             var cols = WddxRecordset.arguments[0];
  679.  
  680.             // Second argument could be the length or the preserve case flag
  681.             var nLen = 0;
  682.             if (WddxRecordset.arguments.length > 1)
  683.             {
  684.                 if (typeof(val = WddxRecordset.arguments[1].valueOf()) == "boolean")
  685.                 {
  686.                     // Case preservation flag is provided as 2nd argument
  687.                     this.preserveFieldCase = WddxRecordset.arguments[1];
  688.                 }
  689.                 else
  690.                 {
  691.                     // Explicitly specified recordset length
  692.                     nLen = WddxRecordset.arguments[1];
  693.  
  694.                     if (WddxRecordset.arguments.length > 2)
  695.                     {
  696.                         // Case preservation flag is provided as 3rd argument
  697.                         this.preserveFieldCase = WddxRecordset.arguments[2];
  698.                     }
  699.                 }
  700.             }
  701.             
  702.             for (var i = 0; i < cols.length; ++i)
  703.             {
  704.                  var colValue = new Array(nLen);
  705.                 for (var j = 0; j < nLen; ++j)
  706.                 {
  707.                     colValue[j] = null;
  708.                 }
  709.             
  710.                 this[this.preserveFieldCase ? cols[i] : cols[i].toLowerCase()] = colValue;
  711.             }
  712.         }
  713.     }
  714. }
  715.  
  716.  
  717. ///////////////////////////////////////////////////////////////////////////
  718. //
  719. // WddxRecordset extensions
  720. //
  721. // The WddxRecordset class has been designed with extensibility in mind.
  722. //
  723. // Developers can add new properties to the object and as long as their
  724. // names are prefixed with _private_ the WDDX serialization function of
  725. // WddxRecordset will not treat them as recordset columns.
  726. //
  727. // Developers can create new methods for the class outside this file as
  728. // long as they make a call to registerWddxRecordsetExtension() with the
  729. // name of the method and the function object that implements the method.
  730. // The WddxRecordset constructor will automatically register all these
  731. // methods with instances of the class.
  732. //
  733. // Example:
  734. //
  735. // If I want to add a new WddxRecordset method called addOneRow() I can
  736. // do the following:
  737. //
  738. // - create the method implementation
  739. //
  740. // function wddxRecordset_addOneRow()
  741. // {
  742. //     this.addRows(1);
  743. // }
  744. //
  745. // - call registerWddxRecordsetExtension() 
  746. //
  747. // registerWddxRecordsetExtension("addOneRow", wddxRecordset_addOneRow);
  748. //
  749. // - use the new function
  750. //
  751. // rs = new WddxRecordset();
  752. // rs.addOneRow();
  753. //
  754. ///////////////////////////////////////////////////////////////////////////
  755.  
  756.  
  757. ///////////////////////////////////////////////////////////////////////////
  758. // registerWddxRecordsetExtension(name, func) can be used to extend 
  759. // functionality by registering functions that should be added as methods 
  760. // to WddxRecordset instances.
  761. function registerWddxRecordsetExtension(name, func)
  762. {
  763.     // Perform simple validation of arguments
  764.     if (typeof(name) == "string" && typeof(func) == "function")
  765.     {
  766.         // Guarantee existence of wddxRecordsetExtensions object
  767.         if (typeof(wddxRecordsetExtensions) != "object")
  768.         {
  769.             // Create wddxRecordsetExtensions instance
  770.             wddxRecordsetExtensions = new Object();
  771.         }
  772.         
  773.         // Register extension; override an existing one
  774.         wddxRecordsetExtensions[name] = func;
  775.     }
  776. }
  777.  
  778.  
  779.  
  780. ///////////////////////////////////////////////////////////////////////////
  781. //
  782. // WddxBinary
  783. //
  784. ///////////////////////////////////////////////////////////////////////////
  785.  
  786.  
  787. ///////////////////////////////////////////////////////////////////////////
  788. // wddxSerialize() serializes a binary value
  789. // returns true/false
  790. function wddxBinary_wddxSerialize(serializer) 
  791. {
  792.     serializer.write(
  793.         "<binary encoding='" + this.encoding + "'>" + this.data + "</binary>");
  794.     return true;
  795. }
  796.  
  797.  
  798. ///////////////////////////////////////////////////////////////////////////
  799. // WddxBinary() constructs an empty binary value
  800. // WddxBinary(base64Data) constructs a binary value from base64 encoded data
  801. // WddxBinary(data, encoding) constructs a binary value from encoded data
  802. function WddxBinary(data, encoding)
  803. {
  804.     this.data = data != null ? data : "";
  805.     this.encoding = encoding != null ? encoding : "base64";
  806.  
  807.     // Custom serialization mechanism
  808.     this.wddxSerialize = wddxBinary_wddxSerialize;
  809. }
  810.  
  811.  
  812.